package com.qf.zmt.resolver;

import com.qf.common.Constants.Constants;
import com.qf.entity.po.LoginMerchant;
import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebArgumentResolver;
import org.springframework.web.context.request.NativeWebRequest;

import javax.servlet.http.HttpServletRequest;

//spring mvc的参数解析器
public class ArgumentResolver implements WebArgumentResolver{

    @Override
    public Object resolveArgument(MethodParameter methodParameter, NativeWebRequest webRequest) throws Exception {
        Class<?> parameterType = methodParameter.getParameterType();
        if(parameterType!=null){
            if(parameterType.equals(LoginMerchant.class)){
                HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class);
                return request.getAttribute(Constants.CURRENT_MERCHANT);
            }
        }
        return UNRESOLVED;
    }
}
